﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace Noria.CFC
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            if (args.Length > 0 && args[0].ToLower() == "/r")
            {
                if (AppUtil.IsAdmin())
                {
                    AppUtil.Register();
                    MessageBox.Show("Register succeeded.", "Register", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("You don't have sufficient privilege!", "Register", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (args.Length > 0 && File.Exists(args[0]))
            {
                Application.Run(new MainForm(args[0]));
            }
            else
            {
                if (MessageBox.Show("Do you want to associate txt file with this application?", "Register", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                {
                    if (AppUtil.IsAdmin())
                    {
                        AppUtil.Register();
                        MessageBox.Show("Register succeeded.", "Register", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        AppUtil.RunElevated(Application.ExecutablePath, "/r");
                    }
                }
            }


        }
    }
}
